package com.firebaselibrary.greendao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.firebaselibrary.bean.IDBean;
import com.firebaselibrary.bean.fireunit.FireUnitAddressBean;
import com.firebaselibrary.bean.fireunit.FireUnitAddressConvert;
import com.firebaselibrary.bean.fireunit.IDBeanConvent;

import com.firebaselibrary.bean.fireunit.FireUnitBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "FIRE_UNIT_BEAN".
*/
public class FireUnitBeanDao extends AbstractDao<FireUnitBean, String> {

    public static final String TABLENAME = "FIRE_UNIT_BEAN";

    /**
     * Properties of entity FireUnitBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Address = new Property(0, String.class, "address", false, "ADDRESS");
        public final static Property Parent = new Property(1, String.class, "parent", false, "PARENT");
        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
        public final static Property Id = new Property(3, String.class, "id", true, "ID");
    }

    private final FireUnitAddressConvert addressConverter = new FireUnitAddressConvert();
    private final IDBeanConvent parentConverter = new IDBeanConvent();

    public FireUnitBeanDao(DaoConfig config) {
        super(config);
    }
    
    public FireUnitBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"FIRE_UNIT_BEAN\" (" + //
                "\"ADDRESS\" TEXT," + // 0: address
                "\"PARENT\" TEXT," + // 1: parent
                "\"NAME\" TEXT," + // 2: name
                "\"ID\" TEXT PRIMARY KEY NOT NULL );"); // 3: id
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"FIRE_UNIT_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, FireUnitBean entity) {
        stmt.clearBindings();
 
        FireUnitAddressBean address = entity.getAddress();
        if (address != null) {
            stmt.bindString(1, addressConverter.convertToDatabaseValue(address));
        }
 
        IDBean parent = entity.getParent();
        if (parent != null) {
            stmt.bindString(2, parentConverter.convertToDatabaseValue(parent));
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(4, id);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, FireUnitBean entity) {
        stmt.clearBindings();
 
        FireUnitAddressBean address = entity.getAddress();
        if (address != null) {
            stmt.bindString(1, addressConverter.convertToDatabaseValue(address));
        }
 
        IDBean parent = entity.getParent();
        if (parent != null) {
            stmt.bindString(2, parentConverter.convertToDatabaseValue(parent));
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(4, id);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3);
    }    

    @Override
    public FireUnitBean readEntity(Cursor cursor, int offset) {
        FireUnitBean entity = new FireUnitBean( //
            cursor.isNull(offset + 0) ? null : addressConverter.convertToEntityProperty(cursor.getString(offset + 0)), // address
            cursor.isNull(offset + 1) ? null : parentConverter.convertToEntityProperty(cursor.getString(offset + 1)), // parent
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // id
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, FireUnitBean entity, int offset) {
        entity.setAddress(cursor.isNull(offset + 0) ? null : addressConverter.convertToEntityProperty(cursor.getString(offset + 0)));
        entity.setParent(cursor.isNull(offset + 1) ? null : parentConverter.convertToEntityProperty(cursor.getString(offset + 1)));
        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
     }
    
    @Override
    protected final String updateKeyAfterInsert(FireUnitBean entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(FireUnitBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(FireUnitBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
